/**
 * @param {number[]} nums
 * @return {boolean}
 */

var canJump = function (nums) {
    let len = nums.length
    let dp = new Array(len).fill(0)
    dp[0] = nums[0]
    for (let i = 1; i < len - 1; i++) {
        if (dp[i - 1] == 0) {
            // 如果前面一个能跳的步数为0 则为0
            dp[i] = 0
        } else {
            dp[i] = Math.max(dp[i - 1] - 1, nums[i])
        }
    }
    if (len === 1) {
        return true
    }
    if(dp[len-2]>0){
        return true
    }else{
        return false
    }
};
canJump([2, 3, 1, 1, 4])